package com.data.center.controller.mongo;
import com.data.center.entity.mongo.MongoPaper;
import com.data.center.service.mongo.MongoPaperService ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/papers")
public class MongoPaperController {
    @Autowired
    private MongoPaperService paperService;

    @GetMapping
    public List<MongoPaper> getAllPapers() {
        return paperService.getAllPapers();
    }

    @GetMapping("/{paperId}")
    public ResponseEntity<MongoPaper> getPaperById(@PathVariable String paperId) {
        Optional<MongoPaper> paper = paperService.getPaperById(paperId);
        return paper.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
    }

    @PostMapping
    public MongoPaper createPaper(@RequestBody MongoPaper paper) {
        return paperService.savePaper(paper);
    }


}
